package top.yokey.android.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.fragment.app.Fragment;

import top.yokey.android.R;
import top.yokey.android.base.App;

public class MineFragment extends Fragment {

    private AppCompatTextView nicknameTextView;
    private AppCompatTextView idTextView;

    private AppCompatTextView logoutTextView;

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_mine, container, false);
        nicknameTextView = root.findViewById(R.id.nicknameTextView);
        idTextView = root.findViewById(R.id.idTextView);
        logoutTextView = root.findViewById(R.id.logoutTextView);
        initEvent();
        return root;
    }

    @Override
    public void onResume() {
        super.onResume();

        nicknameTextView.setText(App.get().getMemberData().getMemberNickname());
        idTextView.setText("手机号：");
        idTextView.append(App.get().getMemberData().getMemberMobile());

    }

    private void initEvent() {

        logoutTextView.setOnClickListener(view -> {
            new AlertDialog.Builder(getActivity())
                    .setTitle("确认您的选择~")
                    .setMessage("注销登录？")
                    .setCancelable(false)//此属性确定是否可以点击其他区域关闭对话
                    .setPositiveButton("确定", (dialogInterface, i) -> {

                    })
                    .setNegativeButton("取消", (dialogInterface, i) -> {

                    })
                    .show();
        });

    }

}
